package com.li.shop.controller;

import com.li.shop.domain.LiuYan;
import com.li.shop.domain.Product;
import com.li.shop.service.LiuYanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/liuyan")

public class LiuYanController {
    @Autowired
    private LiuYanService liuYanService;

    @RequestMapping(value="/liuyanlist",method= RequestMethod.GET)


    public String listLiuYan(Model model){

        List<LiuYan> list1 = liuYanService.listLiuYan();
        model.addAttribute("list", list1);

        //return "back/messagelist";
        return "before/introduction";
    }
    @RequestMapping(value = "/addliuyan", method = RequestMethod.GET)
    public String addMesasagePage(Model model,@RequestParam("id") String id) {
        System.out.println("liu拿到的id为"+id);
        model.addAttribute("id",id);

        return "/back/liuyanadd";

    }

    @RequestMapping(value = "/addliuyan", method = RequestMethod.POST )
//    public String saveLiuYan(LiuYan liuYan, HttpSession session , Model model) {
    public String saveLiuYan(@RequestParam("msId") String msId, @RequestParam("liucontent") String liucontent, HttpSession session , Model model) {
        LiuYan liuYan1=new LiuYan();
        liuYan1.setMsId(msId);
        liuYan1.setLiucontent(liucontent);
        int updated = liuYanService.saveLiuYan(liuYan1);
        Product product=(Product) session.getAttribute("product");
        //String pid=(String)session.getAttribute("pid");
        //String ppid=product.getpId();
       // System.out.println(ppid);
        //System.out.println(product.getpId());
        //model.addAttribute("id",id);
        return "redirect:/product/detail?id="+product.getpId()+"";
        //return "redirect:/user/login";
    }
}
